<template>
	<view class="main" :style="{ 'background-image': `url(${bg})` }">



		<view class="title">
			<view class="bg" :class="title != '' ? 'bg-color' : ''">

				<u-icon @click="goBack" size="32" name="arrow-left"></u-icon>
				<text>{{title}}</text>
				<view class="">
				</view>
			</view>
		</view>

		<view class="">
			<scroll-view :scroll-top="scrollTop" scroll-y="true" class="scroll-Y">
				<view class="container">

					<view class="num-fen">
						分数规则：A.得1分 B.得2分 C.得3分 D.得4分 E.得5分
					</view>
					<!-- 题目和选项 -->
					<view class="" v-for="(item,ind) in questions">
						<view class="question">
							<view class="question-box">
								<view class="question-title">
									<image :src="titBg" mode=""></image>
									<text>{{ind+1}}、</text>
									{{ item.title }}
								</view>
								<view class="question-num">
									{{getOffScores(ind)}}分
								</view>
							</view>

							<view class="question-body">
								<view v-for="(option, index) in item.topic" :key="index" class="option">
									<view class="single-option" :class="{ selected: option.off }"
										:style="{ 'background-image': option.off ? `url(${textBg})` : 'none' }"
										@click="selectAnswer(index)">
										{{ getOptionLabel(index) }}. {{ option.title }}
									</view>
								</view>
							</view>
						</view>
					</view>


				</view>
			</scroll-view>

		</view>



	</view>
</template>

<script>
	
	import {
		getAnswerOne
	} from '../../service/api.js'
	import config from "../../utils/config";
	import submitVue from "../../components/submit.vue";
	import {
		toast,
		getStore,
		setStore,
		removeStore
	} from "@/utils/index";
	export default {
		components: {

			submitVue
		},
		onShareAppMessage(res) {
			return {
				title: '', // 分享的标题
				path: '/outpatient/survey/index', // 分享的页面路径
				imageUrl: '' // 分享的图片路径
			};
		},
		onLoad(options) {
			if (options.id) {
				this.getAnswer(options.id)
				
			}
			console.log(this.bg,"111111111111")

		},
		data() {
			return {
				isModalVisible: false,

				bg: config.ossHost + '2025/01/02/239248ccbed645e1a4321424cbb1d9ff.png',

				titBg: config.ossHost + '2025/01/02/1117162523754c00b8ac36409f53e5d5.png',

				title: "得分详情",
				questions: [],

			}
		},
		computed: {


		},
		methods: {
			goBack() {
				uni.navigateBack({
					delta: 1 // 默认返回上一页，delta 是返回的页面数，默认为 1
				});

			},
			async getAnswer(id) {
				let res = await getAnswerOne(id);
				if (res.code == 200) {
					this.questions = JSON.parse(res.data.answer);
					console.log(this.questions, "11111111111")
				}
			},
			// 获取指定索引的题目，返回第一个off为true的选项的score
			getOffScores(index) {
				const topic = this.questions[index].topic;
				const selectedOption = topic.find(option => option.off === true);
				return selectedOption ? selectedOption.score : null; // 如果没有符合条件的选项，返回null
			},


			// 获取选项的字母
			getOptionLabel(index) {
				const labels = ['A', 'B', 'C', 'D', 'E']; // 定义字母标签
				return labels[index] || ''; // 返回字母标签
			},



		}

	}
</script>

<style lang="scss" scoped>
	.main {
		width: 100%;
		height: 100vh;
		background-size: 100% 100%;
		background-repeat: no-repeat;
		padding-top: 190rpx;
		margin: 0;

		.title {
			position: fixed;
			top: 0;
			left: 0;
			width: 100%;
		}

		.scroll-Y {
			height: calc(100vh - 190rpx);
		}
	}


	.container {
		background: rgba(255, 255, 255, 0.5);
		border-radius: 24rpx 24rpx 0rpx 0rpx;
		padding: 24rpx;


		.num-fen {
			font-size: 28rpx;
			color: #1A1A1A;
			font-weight: 500;
			text-align: center;
		}
	}

	.progress-bar {
		width: 100%;
		height: 10rpx;
		background-color: #f1f1f1;
		border-radius: 5px;

	}

	.progress {
		height: 100%;
		background-color: #1A1A1A;
		border-radius: 16rpx;
	}

	.question {
		margin-top: 24rpx;
		padding: 24rpx;
		background: #fff;
		border-radius: 16rpx;
		border: 1rpx solid #CCA566;

	}

	.question-box {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 40rpx;
	}

	.question-title {
		font-size: 36rpx;
		font-weight: bold;
		display: flex;
		align-items: center;

		image {
			width: 6rpx;
			height: 48rpx;
			margin-right: 10rpx;
		}

	}

	.question-num {
		font-size: 36rpx;
		font-weight: bold;
		color: #805D33;
	}

	.question-body {
		margin-bottom: 20px;
	}

	.option {
		margin-bottom: 24rpx;
	}

	.single-option {
		padding: 0 24rpx;
		line-height: 80rpx;
		color: #4D4D4D;
		font-size: 24rpx;
		height: 80rpx;
		background: #F5F3F0;
		background-size: 100% 100%;
		background-repeat: no-repeat;
		border-radius: 8rpx;
		cursor: pointer;
		box-sizing: border-box;
	}

	.single-option.selected {
		font-weight: bold;
		// background: rgba(204, 165, 102, 0.5);
		color: #1A1A1A;
		height: 80rpx;
		border-radius: 4rpx 4rpx 4rpx 4rpx;
		// border: 2rpx solid #CCA566;
	}

	.single-option:hover {}

	.single-option:disabled {
		background-color: #d3d3d3;
		color: #aaa;
		cursor: not-allowed;
	}

	.bg {
		width: 100%;
		height: 120rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 0 24rpx;
		padding-top: 65rpx;


		.title-img {
			width: 100rpx;
		}

		text {
			display: inline-block;

			color: #1a1a1a;
			font-size: 32rpx;
			font-weight: bold;
		}

		view {
			width: 100rpx;
		}
	}

	.bg-color {
		// background: #fff;
	}
</style>